import request from '@/router/axios';

/**
 * 使用过程
 * this.$ax.axiosGet(url,param)
 */
export function axiosGet(url, params = {}) {
	return new Promise((resolve, reject) => {
		request.get(url, {
			params: params
		})
			.then(response => {
				resolve(response);
			})
			.catch(err => {
				reject(err);
			});
	});
}

/**
 * 封装post请求
 * @param url
 * @param data
 * @returns {Promise}
 */

export function axiosPost(url, data = {}) {
	return new Promise((resolve, reject) => {
		request.post(url, data).then(
			response => {
				resolve(response);
			},
			err => {
				reject(err);
			}
		);
	});
}

export function axiosPut(url, data = {}) {
	return new Promise((resolve, reject) => {
		request.put(url, data).then(
			response => {
				resolve(response.data);
			},
			err => {
				reject(err);
			}
		);
	});
}

export function axiosDel(url, params = {}) {
	return new Promise((resolve, reject) => {
		request.delete(url, {
			params: params
		})
			.then(response => {
				resolve(response);
			})
			.catch(err => {
				reject(err);
			});
	});
}
